package com.zygh.policeasset.controller;

import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.mapper.DictDataMapper;
import com.zygh.policeasset.pojo.dto.AppQrCodeDistributionDTO;
import com.zygh.policeasset.service.AssetsService;
import com.zygh.policeasset.service.QrCodeGeneratedService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/app"})
@Api(tags = {"app接口"})
@RestController
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/controller/AppController.class */
public class AppController {
    @Autowired
    QrCodeGeneratedService qrCodeGeneratedService;
    @Autowired
    DictDataMapper dictDataMapper;
    @Autowired
    AssetsService assetsService;

    @RequestMapping(value = {"/findAll"}, method = {RequestMethod.GET})
    @ApiOperation("查询需分配二維碼項目")
    public Object findAll(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize, @RequestParam(value = "type", required = false) String type, @RequestParam(value = "name", required = false) String name, @RequestParam(value = "buildNum", required = false) String buildNum, @RequestParam(value = "sectionId", required = false) Integer sectionId, @RequestParam(value = "qrCode", required = false) String qrCode, @RequestParam(value = "userId", required = false) Integer userId, @RequestParam(value = "status", required = false) Integer status) {
        return this.qrCodeGeneratedService.selectList(pageNum, pageSize, type, name, buildNum, sectionId, null, qrCode, userId, status);
    }

    @RequestMapping(value = {"/QrCodeDistribution"}, method = {RequestMethod.POST})
    @ApiOperation("二维码分配")
    public Object QrCodeDistribution(@RequestBody AppQrCodeDistributionDTO appQrCodeDistributionDTO) {
        String[] integer = appQrCodeDistributionDTO.getQrCodes().split(",");
        for (int i = 0; i < integer.length; i++) {
            if (this.qrCodeGeneratedService.checkQrCode(integer[i]).intValue() > 0) {
                return new CommonResult().validateFailed("该二维码编号已被绑定,请核对：" + integer[i]);
            }
        }
        if (this.qrCodeGeneratedService.appUpdateQrCodeGeneratedId(appQrCodeDistributionDTO).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("操作失败");
    }

    @RequestMapping(value = {"/selectProject"}, method = {RequestMethod.GET})
    @ApiOperation("项目查询")
    public Object selectProject(@RequestParam(value = "type", required = false) String type, @RequestParam(value = "name", required = false) String name, @RequestParam(value = "buildNum", required = false) String buildNum, @RequestParam(value = "sectionId", required = false) Integer sectionId) {
        return this.qrCodeGeneratedService.selectProject(type, name, buildNum, sectionId, null);
    }

    @RequestMapping(value = {"/findBydictType/{dictType}"}, method = {RequestMethod.GET})
    @ApiOperation("通过字典类型查询")
    public Object findBydictType(@PathVariable String dictType) {
        return this.dictDataMapper.findBydictType(dictType);
    }

    @GetMapping({"/getAssetsTypeSumList"})
    @ApiOperation("数据可视化按资产数量查询")
    public CommonResult getAssetsTypeSumList() {
        return this.assetsService.getAssetsTypeSumList();
    }

    @GetMapping({"/lifeCycle"})
    @ApiOperation("资产全生命周期查询统计")
    public CommonResult lifeCycle() {
        return this.assetsService.lifeCycle();
    }
}